package org.client.otdr.rest;

import java.util.Arrays;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.client.otdr.OTDRID;
import org.openems.DoubleArray;
import org.openems.entity.TraceEntity;

import framework.DomainService;
import framework.Utility;
import framework.webserver.ServiceStore;

@Path("/otdrTrace")
public class OtdrTraceResource {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public DoubleArray get(@QueryParam("wavelength") String wavelength, 
    		@QueryParam("pulsewidth") String pulsewidth, 
    		@QueryParam("length") String length) {

    	DomainService service = ServiceStore.get("org.client.otdr.OtdrDomainService");
    	TraceEntity e = (TraceEntity)service.getEntity(OTDRID.get().TRACE);
    	DoubleArray ret = new DoubleArray();
    	ret.data = Arrays.asList(Utility.lesser(e.getData(), Integer.valueOf(length)));
    	return ret;
    }
}
